/*
 * eeprom.c
 *
 * Created: 17/05/2012 10:54:55
 *  Author: Dani
 */ 

#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>

void EEPROMWrite(uint16_t address, uint16_t data)
{
	// Disable interrupts before writing on the EEPROM.
	cli();
	// Wait for the EEPROM to be ready before writing
	eeprom_busy_wait();
	eeprom_write_word((uint16_t*)address, data);
	// Enable interrupts
	sei();
}

uint16_t EEPROMRead(uint16_t address)
{
	// Wait for the EEPROM to be ready
	eeprom_busy_wait();
	return eeprom_read_word((uint16_t*)address);
}